<?php
	error_reporting(0);
	//require_once "login.php";
	require_once "createcart.php";
    require_once 'data/handler.php';
//error_reporting (E_ALL ^ E_NOTICE);
    //require_once 'data/SessionControl.php';
    /*$session = new SessionControl();
    if(!$session->Check()){
        //unset($_SESSION['allow']);
        unset($_SESSION['fprint']);
        unset($_SESSION['salt_']);
    }*/
    session_start();
    if(!isset($_SESSION["isLoggedIn"]) || !($_SESSION["isLoggedIn"] === true)){
        session_unset();
        session_destroy();
    }
	
	//echo $_SESSION["uname"];
?>

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Musique Basse</title>
        <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css" />
        <link rel="stylesheet" type="text/css" href="css/stylesheet.css" />
        <script type="text/javascript" src="js/jquery.min.js"></script>
    </head>
    <body>
		<div id="main" class="page">
            <header>
                <h1><img src="buttons/logo.png"/></h1>
                <h6>A music store for all kinds of music listeners</h6>
                <nav>
                    <a href="index.php"><img src="buttons/home.png"/></a>
                    <a href="products.php"><img src="buttons/products.png"/></a>
                    <!--accessible or shown only to logged in users-->
                    <?php //var_dump($_SESSION);
                        
                        if(!isset($_SESSION["isLoggedIn"]) || !($_SESSION["isLoggedIn"] === true))
                            echo '<a href="login.php" class="fltright"><img src="buttons/login.png"/></a>';
                        else{
                            echo '<a href="account.php"><img src="buttons/account.png"/></a>';
                            if(isAdmin($_SESSION["uname"]))
                                echo ' <a href="admin.php"><img src="buttons/admincp.png"/></a>';
							echo '<a href="cart.php"><img src="buttons/Cart.png"/></a>';
                            echo '<a href="logout.php" class="fltright"><img src="buttons/logout.png"/></a>';
                        }
                    ?>
                </nav>
            </header>
            
            <div id="content" align="left">
				<div class="head1">
					<img src="buttons/naa.png" id ="naa"/>
				</div>
				<div id="nsong">
					<div class="image">
					<?php					
						$doc = new DOMDocument();
						$doc->load('data/products.xml');
						$xpath = new DOMXPath($doc);
					
						$img = $xpath->query('/albums/album[last()]/albumart')->item(0)->nodeValue;
							echo '<a href="album.php?album='.$xpath->query('/albums/album[last()]/id')->item(0)->nodeValue.'"><img src="'.$img.'" width="300" height="300"/></a><br/>';
						?>
					</div>
					<div class="tex">
					<?php					
						$doc = new DOMDocument();
						$doc->load('data/products.xml');
						$xpath = new DOMXPath($doc);
					
					echo 'Album Title: <a href="album.php?album='.$xpath->query('/albums/album[last()]/id')->item(0)->nodeValue.'">'.$xpath->query('/albums/album[last()]/albumtitle')->item(0)->nodeValue.'</a><br/>';
					echo "Artist: ".$xpath->query('/albums/album[last()]/artist')->item(0)->nodeValue."<br/>";
					echo "Genre: ".$xpath->query('/albums/album[last()]/genre')->item(0)->nodeValue."<br/>";
					echo "Year: ".$xpath->query('/albums/album[last()]/year')->item(0)->nodeValue."<br/>";
					echo $xpath->query('/albums/album[last()]/desc')->item(0)->nodeValue."<br/><br/>";
					echo "Some songs includes: ". $xpath->query('/albums/album[last()]/songs/song[last()]/title')->item(0)->nodeValue.", ". $xpath->query('/albums/album[last()]/songs/song[last()-6]/title')->item(0)->nodeValue." & ".$xpath->query('/albums/album[last()]/songs/song[last()-3]/title')->item(0)->nodeValue."<br/> ";
					?>
					</div>
				</div>
				<div id="topten">
				<img src="buttons/hot.png" id="hot"/>
				<div id="top10">
				<?php
					//init dom
					$doc = new DOMDocument();
					$doc->load('data/products.xml');
					//init xpath (for easy traversal)
					$xpath = new DOMXPath($doc);
					//traverse dom tree
					$results = $xpath->query('//albums/album/songs/song/title');
					//init top songs array
					foreach($results as $result) 
						$songrank[$result->nodeValue] = $result->parentNode->getAttribute('hits').'<br>';

					//sort by values then keys
					$k = array_keys($songrank);
					$v = array_values($songrank);
					array_multisort($v, SORT_DESC, $k, SORT_ASC);
					$songrank = array_combine($k, $v);
					//get top ten
					$topten = array_slice($songrank,0,10,true);
					$i=1;
					foreach($topten as $key=>$hits) echo $i++.". ".$key.'<br>';
				?>
				</div>
				</div>
					<div class="head1">
						<img id="fa" src="buttons/fa.png"/>
					</div>
				<div id="fsong">
					<div class="image">
						<img src= "albums/symphony_soldier.jpg" width="300px" height="300px"/>
					</div>
					<div class="tex">
						<p>Album Title: <a href="album.php?album=8">Symphony Soldier</a><br/>
							Artist: The Cab<br/>
							Genre: Pop Rock, Alternative Rock, Power Pop<br/>
							Year: 2011<br/>
							Symphony Soldier is the second studio album by American rock band The Cab. It was released on August 23, 2011 as the follow-up to their first album Whisper War in 2008.The album was released independently following the group's departure from Fueled by Ramen/Decaydance Records. The album has received much critical praise, with AbsolutePunk giving Symphony Soldier an extremely positive review with a rating of 95%, calling the album a "masterpiece."
						
						<p>Some songs includes: Living Louder, Intoxicated & Another Me</p>
					</div>
				</div>
            </div>
			
            
            <div class="clear"></div>
            
            <footer>
                <p>Copyright &copy; 2012 KENNICS. All rights reserved.</p>
                <p>Design by Werdnazner</p>
            </footer>
			<br/><br/><br/>
        </div>
    </body>
</html>
